<template>
  <div class="stepBox">
    <div class="cont">
      <basic-form
        :showAlert="false"
        message="请先填写基本信息提交保存后，再上传证照扫描图片"
        :isBtn="false"
        :formInfos="s_FormInfo"
        :formDatas="s_formDatas"
        :rules="s_rules"
        ref="forms"
        @onSubmit="onSubmit"
      ></basic-form>
    </div>
    <div class="btnBox">
      <a-button class="btn" type="primary" @click="nexts()">
        下一步
      </a-button>
    </div>
  </div>
</template>

<script>
import basicForm from '../common/basicForm'
import { saveInfo } from './saleOrder'
const s_FormInfo = [
  { label: '销售单号', name: 'saleOrderNo', type: 'input', placeholder: '请输入销售单号' },
  { label: '采购类型', name: 'saletype', type: 'dicselect', dicName: 'purType', placeholder: '请选择采购类型' },
  { label: '客户名称', name: 'customerName', type: 'input', placeholder: '请输入客户名称' },
  { label: '含税总价(元)', name: 'totalPrice', type: 'input', placeholder: '请输入含税总价(元)' },
  { label: '送货类型',name: 'deliveryType',type: 'dicselect',dicName: 'deliveryType',placeholder: '请选择送货类型'},
  { label: '应收金额', name: 'receivableAmount', type: 'input', placeholder: '请输入应收金额' },
  { label: '税费', name: 'taxes', type: 'input', placeholder: '请输入税费' },
  { label: '已收金额', name: 'paidAmount', type: 'input', placeholder: '请输入已收金额' },
  { label: '收货地址', name: 'deliveryAddr', type: 'input', placeholder: '请输入收货地址' },
  { label: '收货人及电话', name: 'consignee', type: 'input', placeholder: '请输入收货人及电话' },
  // { label: '配送状态', name: 'deliveryState', type: 'dicselect',dicName: 'deliveryState',  placeholder: '请选择配送状态' },
  // { label: '开票状态', name: 'invoiceState', type: 'dicselect',dicName: 'invoiceState',  placeholder: '请选择开票状态' },
  // { label: '订单状态', name: 'purOrderState', type: 'dicselect',dicName: 'purOrderState',  placeholder: '请选择订单状态' },
  { label: '采购单位备注', name: 'remarks', type: 'textarea', placeholder: '请输入采购单位备注' },
  { label: ['保存', '重置'], type: 'botton' }
]
const s_formDatas = {
  sysSeq: 0,
  pid: '',
  saleOrderNo: null,
  saletype: null,
  customerName: null,
  totalPrice: null,
  deliveryType: null,
  receivableAmount: null,
  taxes: null,
  paidAmount: null,
  deliveryAddr: null,
  consignee: null,
  remarks: null,
  undefined: null
}
const s_rules = {
  saleOrderNo: [{ required: true, message: '销售单号必填', trigger: 'blur' }],
  deliveryAddr: [{ required: true, message: '收货地址必填', trigger: 'blur' }]
}
export default {
  props: {},
  components: {
    basicForm
  },
  data() {
    return {
      s_FormInfo: s_FormInfo,
      s_formDatas: s_formDatas,
      s_rules: s_rules,
      isSubmit: false
    }
  },
  created() {},
  mounted() {
    this.autoFormData()
    console.log('000000000')
    this.s_formDatas = {
      sysSeq: 0,
      pid: '',
      saleOrderNo: null,
      saletype: null,
      customerName: null,
      totalPrice: null,
      deliveryType: null,
      receivableAmount: null,
      taxes: null,
      paidAmount: null,
      deliveryAddr: null,
      consignee: null,
      remarks: null,
      undefined: null
    }
  },

  methods: {
    //自动生成FormData
    autoFormData() {
      let str = ''
      for (const item of s_FormInfo) {
        str += item.name + ': null,'
      }
      console.log(str)
    },
    nexts() {
      this.$refs.forms.submitForm()
    },
    onSubmit(val) {
      if (this.isSubmit) {
        this.$emit('nextStep')
      } else {
        this.saveObjInfo(val)
      }
    },
    // 保存详细信息
    async saveObjInfo(val) {
      // this.$message.loading({ content: '提交中'， })
      let res = await saveInfo(val)
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        this.$message.success({ content: '保存成功', duration: 2 })
        this.isSubmit = true
        this.$emit('nextStep', res.data)
      } else {
        this.$message.error({ content: '保存失败', duration: 2 })
      }
    },
  }
}
</script>

<style scoped>
.stepBox {
  width: 100%;
  height: 100%;
  position: relative;
}
.cont {
  padding-left: 5px;
  max-height: calc(70vh - 40px);
  overflow-y: scroll;
}
.btnBox {
  height: 7vh;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  /* border: 1px solid #eee; */
  position: absolute;
  bottom: 0px;
}
</style>
